﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Common.LoggingManager
{
    public sealed class Logger
    {
        public static void Log(string message)
        {
            try
            {
                log4net.ILog logger = log4net.LogManager.GetLogger("Default");
                logger.Error(message);
            }
            catch
            {
                //Do nothing
            }
        }

        public static void LogException(Exception ex)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger("Default");
            try
            {
                if (ex != null)
                {
                    logger.Error("Exception: " + ex.Message + "\n\r Stack Trace: " + ex.StackTrace + "\n\r ::: ");

                    if (ex.InnerException != null)
                    {
                        logger.Error(string.Format(" caused by Inner Exception: {0}\n\r Stack Trace: {1}", ex.InnerException.Message, ex.InnerException));
                    }
                }
                else
                    logger.Error("Exception is NULL");
            }
            catch (Exception exx)
            {
                logger.Error(exx.Message);
            }
        }

        public static void LogException(string definition, Exception ex)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger("Default");
            try
            {
                if (ex != null)
                {
                    logger.Error(definition + "Exception: " + ex.Message + "\n\r Stack Trace: " + ex.StackTrace + "\n\r ::: User:");

                    if (ex.InnerException != null)
                    {
                        logger.Error(string.Format(" caused by Inner Exception: {0}\n\r Stack Trace: {1}", ex.InnerException.Message, ex.InnerException));
                    }
                }
                else
                    logger.Error("Exception is NULL");
            }
            catch (Exception exx)
            {
                logger.Error(exx.Message);
            }
        }

    }
}
